////////////////////////////////////////////////////////////////////////////////
///////// Inflexibility and Corporate Credit Spreads ///////////////////////////
///////// Zhe An, Abe de Jong, Ying Xia, Zhaofeng Xu ///////////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
* Date: May 5, 2025
* This do file contains code generating results for Figures 1 to 3
* Please define the path for datasets and the path for storing results before running the following program. 
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////


********************************************************************************
* Figure 1 Regression Discontinuity Plots for Ex-post Credit Spreads and Inflexibility
********************************************************************************

* Panel A - Figure 1
rdplot future2_inflex m_vote_rate_decimal, c(0.5) p(3) ci(90) nbins(0 2) graph_options(l1title(Ex-post Inflexibility)  b1title(Percentage of Favorable Votes))
graph save rd1,  replace
* Panel B - Figure 1
rdplot future2_yield m_vote_rate_decimal, c(0.5) p(3) ci(90)  nbins(0 2)  graph_options(l1title(Ex-post Credit Spreads) b1title(Percentage of Favorable Votes))
graph save rd2,  replace


********************************************************************************

********************************************************************************
* Figure 2 Alternative RDD Bandwidth
********************************************************************************

* Panel A - Graph 2
rdrobust future2_inflex  m_vote_rate_decimal , c(0.5)   //find optimal bandwidth 
local h = e(h_l)   //obtain optimal bandwidth 
ereturn list  
forvalues i=1(1)12{
local hrobust= `h'*0.25*`i'
rdrobust future2_inflex m_vote_rate_decimal ,h(`hrobust') c(0.5) level(90)
estimates store esti`i'
}

* output graph 
coefplot (esti1, mcolor(black)  ciopts(lcolor(black))) (esti2, mcolor(black)  ciopts(lcolor(black))) (esti3, mcolor(black)  ciopts(lcolor(black))) (esti4, mcolor(black)  ciopts(lcolor(black))) ///
(esti5, mcolor(black)  ciopts(lcolor(black))) (esti6, mcolor(black)  ciopts(lcolor(black))) (esti7, mcolor(black)  ciopts(lcolor(black))) ///
(esti8, mcolor(black)  ciopts(lcolor(black))) (esti9, mcolor(black)  ciopts(lcolor(black))) (esti10, mcolor(black)  ciopts(lcolor(black)))  ///
(esti11, mcolor(black)  ciopts(lcolor(black))) (esti12, mcolor(black)  ciopts(lcolor(black)))  , ///
yline(0) xline(0) drop(_cons) vertical ytitle("Estimate of Ceofficient") xtitle("% of Imbens and Kalyanaraman(2012) Optimal Bandwidth") graphregion(fcolor(white))   ciopts(recast(rcap))  

* Panel B - Graph 2
rdrobust future2_yield  m_vote_rate_decimal , c(0.5)   //find optimal bandwidth 
local h = e(h_l)   //obtain optimal bandwidth 
ereturn list  
forvalues i=1(1)12{
local hrobust= `h'*0.25*`i'
rdrobust future2_yield m_vote_rate_decimal ,h(`hrobust') c(0.5) level(90)
estimates store esti`i'
}

* output graph 
coefplot (esti1, mcolor(black)  ciopts(lcolor(black))) (esti2, mcolor(black)  ciopts(lcolor(black))) (esti3, mcolor(black)  ciopts(lcolor(black))) (esti4, mcolor(black)  ciopts(lcolor(black))) ///
(esti5, mcolor(black)  ciopts(lcolor(black))) (esti6, mcolor(black)  ciopts(lcolor(black))) (esti7, mcolor(black)  ciopts(lcolor(black))) ///
(esti8, mcolor(black)  ciopts(lcolor(black))) (esti9, mcolor(black)  ciopts(lcolor(black))) (esti10, mcolor(black)  ciopts(lcolor(black)))  ///
(esti11, mcolor(black)  ciopts(lcolor(black))) (esti12, mcolor(black)  ciopts(lcolor(black)))  , ///
yline(0) xline(0) drop(_cons) vertical ytitle("Estimate of Ceofficient") xtitle("% of Imbens and Kalyanaraman(2012) Optimal Bandwidth") graphregion(fcolor(white))   ciopts(recast(rcap))  


********************************************************************************

********************************************************************************
* Figure 3 Placebo Test
********************************************************************************

* Panel A
* Set the number of placebo regressions
* Notes: maximum storage=300 for each try; To run 1,000 regressions, please change threshold randomly as well 
local nplacebos = 200  

* Initialize an empty list for the model names 
local model_list 

* Loop to run placebo regressions and store results
forvalues i = 1/`nplacebos' {
    * Generate a random placebo cutoff other than 0.5 (true threshold) - Please change threshold here 
    local placebo_cutoff = round(runiform(0.3, 0.4999), 0.01) 

    * Run the placebo RDD regression for the generated cutoff
    rdrobust future2_inflex m_vote_rate, c(`placebo_cutoff') p(3)

    * Store each placebo regression result
    estimates store placebo_model_`i'

    * Add the current model to the list of models
    local model_list `model_list' placebo_model_`i'
}

* Export coefficients (b)
esttab `model_list' using "coefficients_output.csv", replace   cells("b")   title("Placebo Models: Coefficients (b)")   nogaps


* Panel B
* Set the number of placebo regressions
* Notes: maximum storage=300 for each try; To run 1,000 regressions, please change threshold randomly as well 
local nplacebos = 200  

* Initialize an empty list for the model names 
local model_list 

* Loop to run placebo regressions and store results
forvalues i = 1/`nplacebos' {
    * Generate a random placebo cutoff other than 0.5 (true threshold) - Please change threshold here 
    local placebo_cutoff = round(runiform(0.3, 0.4999), 0.01) 

    * Run the placebo RDD regression for the generated cutoff
    rdrobust future2_yield m_vote_rate, c(`placebo_cutoff') p(3)

    * Store each placebo regression result
    estimates store placebo_model_`i'

    * Add the current model to the list of models
    local model_list `model_list' placebo_model_`i'
}

* Export coefficients (b)
esttab `model_list' using "coefficients_output.csv", replace   cells("b")   title("Placebo Models: Coefficients (b)")   nogaps



********************************************************************************

////////////////////////////////////////////////////////////////////////////////
* The above codes generate the result, and the format of table is finalised in Excel. 
* Placebo test may not generate exact figure since every regressions use randomly threshold other than 50% of true shreshold. 

////////////////////////////////////////////////////////////////////////////////
